package com.app.Tree;


import android.app.Dialog;
import android.content.Context;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.app.Activity.R;

public class NoteDialog extends Dialog implements android.view.View.OnClickListener {
	MyHandlerInterface OKClickListener;
	MyHandlerInterface CancelClickListener;
	private String note;
	EditText txtNode;
	Button btnOK, btnCancel;
	private Object myObj;
	
	public NoteDialog(Context context,boolean readOnly) {
		super(context);
		this.setContentView(R.layout.layout_note_dialog);	
		this.setTitle("Ghi chú");
		txtNode=(EditText)findViewById(R.id.txtNote);
		btnCancel = (Button) findViewById(R.id.btnCancel);
		btnOK = (Button) findViewById(R.id.btnOK);
		
		btnCancel.setOnClickListener(this);
		btnOK.setOnClickListener(this);
		
		if(readOnly){
			btnOK.setVisibility(View.GONE);
			btnCancel.setText("Đóng");
			txtNode.setKeyListener(null);
		}
	}

	@Override
	public void onClick(View v) {
		int id = v.getId();
		switch (id) {
		case R.id.btnOK:
			this.note = txtNode.getText().toString();			
			if(OKClickListener!=null)
		         OKClickListener.onHandle(myObj);
			break;
		default:			
			if(CancelClickListener!=null){
				CancelClickListener.onHandle(myObj);
			}
			break;
		}
		dismiss();
	}

	public String getNote() {
		return note;
	}

	public void setNote(String note) {
		this.note = note;
		this.txtNode.setText(note);
	}

	public MyHandlerInterface getOKClickListener() {
		return OKClickListener;
	}

	public void setOKClickListener(MyHandlerInterface oKClickListener) {
		OKClickListener = oKClickListener;
	}

	public MyHandlerInterface getCancelClickListener() {
		return CancelClickListener;
	}

	public void setCancelClickListener(MyHandlerInterface cancelClickListener) {
		CancelClickListener = cancelClickListener;
	}

}
